import java.util.*;

public class RoundRobinScheduler extends LinkedList<Process> {
	   
	private static final long serialVersionUID = 1L;
	
	public RoundRobinScheduler() {	    
	}
	
	/**
	 * Pop the first element and add it to the end of the queue.
	 */
	public void advance() {
		if (this.size() > 1) {
			Collections.rotate(this, 1);
		}			
	}
	
	public void advacne(List<Process> subList) {
		if (this.size() > 1) {
			Collections.rotate(this, 1);
		}	
	}

	/**
	 * Pop the first element and add it to the end of the queue.
	 */
	public void advance(int distance) {
		if (this.size() > 1) {
			Collections.rotate(this, distance);
		}			
	}
	/**
	 * Checks if this is a valid processId.
	 * @param processId
	 * @return
	 */
	public boolean isValidProcessId(int processId) {
		boolean validProcessId = false;
		for (Process process : this) {
			if (process.getProcessId() == processId)
				return true;
		}
		return validProcessId;
	}
	
	/**
	 * Return a process from a processId.
	 * @param processId
	 * @return
	 */
	public Process getProcessByProcessId(int processId) {
		Process pro = null;
		for (Process process : this) {
			if (process.getProcessId() == processId) {
				pro = process;
				return pro;
			}	
		}
		return pro;
	}
	
	/**
	 * Set the process by processId.
	 * @param processId
	 * @param process
	 * @return
	 */
	public boolean setProcessByProcessId(int processId, Process process) {
		for (Process pro : this) {
			if (pro.getProcessId() == processId) {
				int pIndex = this.indexOf(pro);
				this.set(pIndex, process);
				return true;				
			}				
		}
		return false;		
	}
	
}
